﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System .Net ;
using System .Net .Mail ;



namespace 视频设备
{
    public class Util
    {
        public enum Result
        {
            Success,OverTime
        }

        //发送邮件
        public static void sendEmail(string name, string email,string time)
        {
            string Str1 = "您收到这封这封电子邮件是因为您 (也可能是某人冒充您的名义) 申请了一个新的密码.假如这不是您本人所申请, 请不用理会这封电子邮件, 但是如果您持续收到这类的信件骚扰, 请您尽快联络管理员";
            string Str2 = "要使用新的密码, 请使用以下链接启用密码.";
            string Str3 = "(如果无法点击该URL链接地址,请将它复制并粘帖到浏览器的地址输入框,然后单击回车即可.该链接使用后将立即失效.)";
            string Str4 = " 注意:请您在收到邮件1个小时内使用,否则该链接将会失效.";
            string Str5 = "我们将一如既往、热忱的为您服务!";
            string Str6 = "用户服务支持：webmaster@csdn.net";
            string url = "http://localhost:4366/重置密码.aspx?username=" + name+"&time="+time ;
            string to = email;
            string from = "13821038913@163.com";           
            MailMessage message = new MailMessage(from, to);
            message.SubjectEncoding = System.Text.Encoding.Default;
            message.BodyEncoding = System.Text.Encoding.Default;
            message.Subject = "找回密码";
            message.Body = "尊敬的" + name + "您好!" + "<br>" + Str1 + "<br>" + Str2 + "<br>" + "<a href='" + url  + "'>" + url + "</a>" + "<br>" + Str3 + "<br>" + Str4 + "<br>" + Str5 + "<br>" + Str6;             
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.163.com";
            client.Credentials = new NetworkCredential("13821038913", "Nanwang2008");
            client.Send(message);
        }
            

        ////使用Jmail方法发送邮件
        //public static void sendEmail(string name, string email,string mima)
        //{                      
        //        jmail.Message jmessage = new jmail.Message();
        //        jmessage.Charset = "GB2312";
        //        jmessage.ContentType = "text/plain";
        //        jmessage.From = "13821038913@163.com";
        //        //发信地址
        //        jmessage.MailServerUserName = "13821038913";
        //        jmessage.MailServerPassWord = "Nanwang2008";
        //        jmessage.FromName = "亚楠";
        //        jmessage.ReplyTo = "13821038913@163.com";
        //        jmessage.Subject = "找回密码";
        //        //内容
        //        string strbody = "尊敬的"+name  + "您好!您的密码为:" + mima;
        //        jmessage.Body = strbody;
        //        // 邮件标题
        //        jmessage.AddRecipient(email, "", "");
        //        jmessage.Send("smtp.163.com", false);
        //        jmessage.Close();           
        //}

        //提示、报错
        public static void AlertString(string content, HttpResponse Response)
        {
            Response.Write( "<script language='javascript'>alert(" + "'" + content + "'" + ");</script>");         
        }

        //判断时间
        public static void JudgeTime()
        {
           var firsttime=DateTime.Now.ToShortTimeString();
           var url = "视频.aspx?timeStaamp=" + firsttime;

        }


        //提取url中用户名参数
        public static string UserName()
        {
            //获取单个参数
            string name = HttpContext.Current.Request.QueryString["username"];
            //获取之后的所有参数        
            return name;
        }

        //提取url中的时间
        public static string UserTime()
        {
            string  time = HttpContext.Current.Request.QueryString["time"];
            return time;
        }


        //判断是否超时
        public static Result OverTime(DateTime nowtime)
        {
            var time = UserTime();           
            DateTime oldtime = DateTime.Parse(time);
            if (oldtime >= nowtime)
            {
                return Result.Success;
            }
            else
            {
                return Result.OverTime;
            }
        }

    }
}